/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.asportoonline.tags;

import java.util.List;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import org.asportoonline.entities.Locale;

/**
 *
 * @author Luca
 */
public class LocaliVenditoreTag extends SimpleTagSupport {
    private List<Locale> locali;

    /**
     * Get the value of locali
     *
     * @return the value of locali
     */
    public List<Locale> getLocali() {
        return locali;
    }

    /**
     * Set the value of locali
     *
     * @param locali new value of locali
     */
    public void setLocali(List<Locale> locali) {
        this.locali = locali;
    }

    /**
     * Called by the container to invoke this tag. 
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        List<Locale> ll = getLocali();
        Locale l;
        String link;
        String indirizzo;
        String[] chiusura = {"Nessuno", "Luned&igrave;", "Marted&igrave;", "Mercoled&igrave;", "Gioved&igrave;", "Venerd&igrave;", "Sabato", "Domenica"};
        String orario = "";
        
        try {
            
             if(ll==null || ll.isEmpty()) {     
                out.print("<p>Nessun locale registrato!</p>");
            }
            else {
                for(int i=0; i<ll.size(); i++) {
                    l = ll.get(i);
                    link = "MainController?q=fetch_restaurant_details_action&ret=restaurant_details&idlocale="+l.getIdLocale();
                    indirizzo = l.getIndirizzo().getVia() + ", " + l.getIndirizzo().getCitta();
                    
                    if(l.getSecondaApertura()!=null && !l.getSecondaApertura().isEmpty()) {
                        orario = "Orario";
                    }
                    else {
                        orario = "Orari";
                    }
                    
                    out.print("    <div class=\"riassuntoLocale\">\n"                   
                            + "        <div class=\"logoL\">"
                            + "            <a href=\"" + link + "\"><img src=\"img/" + l.getUrlimmagine() + "\" alt=\""+ l.getNome() +"\" /></a>\n"
                            + "        </div>\n"
                            + "        <div class=\"infoR\">\n"
                            + "            <div class=\"datiU\">\n"
                            + "                <h6><a href=\"" + link + "\">" + l.getNome() + "</a></h6>\n"
                            + "                " + indirizzo + "\n"
                            + "            </div>\n"
                            + "            <div class=\"datiD\">\n"
                            + "                <ul class=\"listaDati\">\n"
                            + "                    <li>\n"
                            + "                        <ul class=\"dato\">\n"
                            + "                            <li><h6>" + orario + " di apertura</h6></li>\n"
                            + "                            <li>" + l.getPrimaApertura() + "</li>\n");
                if(l.getSecondaApertura()!=null && !l.getSecondaApertura().isEmpty()) {
                    out.print("                            <li>" + l.getSecondaApertura() + "</li>\n");
                }
                    out.print("                        </ul>\n"
                            + "                    </li>\n"
                            + "                    <li>\n"
                            + "                        <ul class=\"dato\">\n"
                            + "                            <li><h6>Giorno di chiusura</h6></li>\n"
                            + "                            <li>" + chiusura[l.getGiornoChiusura()+1] + "</li>\n"
                            + "                        </ul>\n"
                            + "                    </li>\n"
                            + "                    <li>\n"
                            + "                        <ul class=\"dato\">\n"
                            + "                            <li><h6>Distanza massima<br />di consegna</h6></li>\n"
                            + "                            <li>" + l.getDistanzaMassima() + "km </li>\n"
                            + "                        </ul>\n"
                            + "                    </li>\n"
                            + "                    <li>\n"
                            + "                        <ul class=\"dato\">\n"
                            + "                            <li><h6>Email</h6></li>\n"
                            + "                            <li>" + l.getEmail() + "</li>\n"
                            + "                        </ul>\n"
                            + "                    </li>\n"
                            + "                    <li>\n"
                            + "                        <ul class=\"dato\">\n"
                            + "                            <li><h6>Telefono</h6></li>\n"
                            + "                            <li>" + l.getTelefono() + "</li>\n"
                            + "                        </ul>\n"
                            + "                    </li>\n"
                            + "                </ul>\n"
                            + "            </div>\n"
                            + "        </div>\n"
                            + "    </div>\n");
                                                                    
                }
                out.flush();                
            }
        } catch (java.io.IOException ex) {
            throw new JspException("Error in LocaliTag tag", ex);
        }
    }
}
